/**
 * 
 */
package edu.umd.clip.lm.tools;

import java.io.*;

import javax.xml.parsers.*;

import org.w3c.dom.*;
import org.xml.sax.SAXException;

import edu.berkeley.nlp.util.*;

import edu.umd.clip.lm.util.tree.*;
import edu.umd.clip.lm.model.*;

/**
 * @author Denis Filimonov <den@cs.umd.edu>
 *
 */
public class DumpLambdas {
	public static class Options {
        @Option(name = "-tree", required = true, usage = "history tree XML file")
		public String tree;      
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
        OptionParser optParser = new OptionParser(Options.class);
        Options opts = (Options) optParser.parse(args, true);
        
		BinaryTree<HistoryTreePayload> root = LanguageModel.loadXMLHistoryTree(opts.tree);
		
		int maxClusterId = 0;
		for(BinaryTreeIterator<HistoryTreePayload> it = root.getPostOrderIterator(); it.hasNext(); ) {
			int clusterId = it.next().clusterid;
			if (clusterId > maxClusterId) maxClusterId = clusterId;
		}

		double lambdas[] = new double[maxClusterId+1];
		for(BinaryTreeIterator<HistoryTreePayload> it = root.getPostOrderIterator(); it.hasNext(); ) {
			HistoryTreePayload payload = it.next();
			lambdas[payload.clusterid] = payload.lambda;
		}
		
		for(double lambda : lambdas) {
			System.out.println(lambda);
		}
	}

}
